package com.example.common.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author Liaorun
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "统一返回结构")
public class R<T> {
    public static final int CODE_SUCCESS = 20000;
    public static final int CODE_FAILED = 40000;

    @ApiModelProperty(value = "是否成功")
    private boolean success;

    @ApiModelProperty(value = "状态码")
    private int code;

    @ApiModelProperty(value = "描述")
    private String msg;

    @ApiModelProperty(value = "数据")
    private T data;


    public static R SUCCESS(String msg) {
        R r = new R();
        r.code = CODE_SUCCESS;
        r.msg = msg;
        return r;
    }

    public static R SUCCESS(String msg, Object data) {
        R r = new R();
        r.code = CODE_SUCCESS;
        r.msg = msg;
        r.data = data;
        return r;
    }

    public static R Error() {
        return Error("失败", null);
    }

    public static R Error(String msg, Object data) {
        R r = new R();
        r.code = CODE_SUCCESS;
        r.msg = msg;
        r.data = data;
        return r;
    }

}
